package com.minhang.service.impl;
import com.minhang.mapper.EmployeeMapper;
import com.minhang.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


/**
 * 员工
 *
 * @author rookie
 */
@Service
@Slf4j
public class EmployeeServiceImpl implements UserDetailsService, EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * 登录
     *
     * @param username
     * @return
     * @throws UsernameNotFoundException
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        log.info("参数 ，email={}", username);
        // 判断接受的邮箱是否为空
        if (!("".equals(username)) && username != null) {
            // 查询数据库
            UserDetails employee = employeeMapper.selectByEmail(username);
            // 判断对象是否为空
            if (employee == null) {
                throw new UsernameNotFoundException("用户不存在");
            }
            return employee;
        }
        throw new UsernameNotFoundException("用户不存在");
    }


}
